Skip to content

llvm2alive: do not skip range and initializes param attributes - #1394

Merged
nunoplopes merged 1 commit into
AliveToolkit:masterfrom
cjsrxzdyzds:fix-param-range-attr
Nov 26, 2026
Merged

nunoplopes merged 1 commit into
AliveToolkit:masterfrom
cjsrxzdyzds:fix-param-range-attr

Conversation

@cjsrxzdyzds

Copy link
Copy Markdown
Contributor

#1352 added a check at the top of handleParamAttrs that lets only enum, int and type attributes reach the switch, so that string attributes no longer reach getKindAsEnum(). range and initializes are constant range attributes, so their cases in the switch became unreachable, and both have been ignored on parameters since then.

For example, this incorrect transformation verifies:

define i8 @src(i8 %x) {
  ret i8 %x
}

define i8 @tgt(i8 range(i8 0, 10) %x) {
  ret i8 %x
}

and this correct one reports a value mismatch:

define i8 @src(i8 noundef range(i8 1, 2) %x) {
  ret i8 %x
}

define i8 @tgt(i8 noundef range(i8 1, 2) %x) {
  ret i8 1
}

The existing test alive-tv/uscmp.srctgt.ll, which has range parameters, fails for the same reason.

Skip only string attributes, as #1352 intended.

Assisted-by: Claude Code

AliveToolkit#1352 made handleParamAttrs skip every attribute that is not an enum,
int or type attribute, to keep string attributes away from
getKindAsEnum(). That also skips the constant range attributes, so the
Range and Initializes cases of the switch became unreachable and a
range or initializes attribute on a parameter was silently ignored.

Skip only string attributes, as intended.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nunoplopes
nunoplopes merged commit e0dec9c into AliveToolkit:master Nov 26, 2026
nunoplopes pushed a commit that referenced this pull request Dec 1, 2026
A `range` attribute on a `noundef` parameter becomes a well-defined
`AssumeVal`, which is UB when the value is out of range.
`AssumeVal::hasSideEffects()` returns false, so the transform deletes
it, together with the UB, when the function does not use the parameter.
That function is then treated as defined for every argument. The path is
reachable again since #1394.

For example, this correct transformation reports "Source is more defined
than target":

```llvm
define i8 @src(i8 noundef range(i8 4, 8) %x) {
  ret i8 0
}

define i8 @tgt(i8 noundef range(i8 4, 8) %x) {
  %d = sub i8 %x, 4
  %in = icmp ult i8 %d, 4
  call void @llvm.assume(i1 %in)
  ret i8 0
}
```

Make `hasSideEffects()` return `is_welldefined`, as `BinOp` does for
division. `!range` metadata on loads is not affected, because it is
lowered to a separate `assume_welldefined`.

Assisted-by: Claude Code

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants